package com.laiyizhan.cms.first.controller;

import com.laiyizhan.cms.first.request.SixthRequest;
import com.laiyizhan.cms.first.service.impl.SixthServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * Created by SoulWolf on 2017/7/21.
 */
@Controller
@RequestMapping("/admin")
public class SixthController {

    @Autowired
    SixthServiceImpl sixthService;


    /*目录页面*/
    @RequestMapping(value = "/sixth/index/show")
    public String Fifth_index(SixthRequest request,HttpSession httpSession,ModelMap modelMap) {
        request.setoName((String)httpSession.getAttribute("oName"));
        httpSession.setAttribute("number", 1);
        modelMap.put("state",sixthService.Sixth_index(request));
        return "/sixth/index";
    }


    /*一个用于返回页面，一个用于提交页面*/
    @RequestMapping(value = "/sixth/a/show")
    public String sixth_a(SixthRequest request) {
        return "/sixth/main";
    }
    @RequestMapping(value = "/sixth/a")
    public String Sixth_a_record(SixthRequest request, HttpSession httpSession,ModelMap modelMap) {
        request.setoName((String)httpSession.getAttribute("oName"));
        String result = sixthService.Sixth_a(request);
        modelMap.put("state",sixthService.Sixth_index(request));
        if(result=="no"){
            modelMap.put("error","当职称人数不为0的时候，该职称的在职工年人均工资也不能为0");
            modelMap.put("link","/admin/sixth/a/show");
            return "/error/error";
        }
        return "/sixth/b";
    }

    @RequestMapping(value = "/sixth/b/show")
    public String Sixth_b() {
        return "/sixth/b";
    }
    @RequestMapping(value = "/sixth/b")
    public String Sixth_b_record(SixthRequest request,ModelMap modelMap,HttpSession httpSession) {
        request.setoName((String)httpSession.getAttribute("oName"));
        sixthService.Sixth_b(request);
        modelMap.put("state",sixthService.Sixth_index(request));
        return "/sixth/c";
    }

    @RequestMapping(value = "/sixth/c/show")
    public String Sixth_c() {
        return "/sixth/c";
    }
    @RequestMapping(value = "/sixth/c")
    public String Sixth_c_record(SixthRequest request,HttpSession httpSession,ModelMap modelMap) {
        request.setoName((String)httpSession.getAttribute("oName"));
        int order = (int)httpSession.getAttribute("number");
        sixthService.Sixth_c(request);
        modelMap.put("state",sixthService.Sixth_index(request));
        if(order<5){
            httpSession.setAttribute("number",order+1);
        }else{
            return "sixth/d";
        }
        return "/sixth/c";
    }

    @RequestMapping(value = "/sixth/d/show")
    public String Sixth_d() {
        return "/sixth/d";
    }
    @RequestMapping(value = "/sixth/d")
    public String Sixth_d_record(SixthRequest request,ModelMap modelMap,HttpSession httpSession) {
        request.setoName((String)httpSession.getAttribute("oName"));
        sixthService.Sixth_d(request);
        modelMap.put("state",sixthService.Sixth_index(request));
        return "/sixth/e";
    }

    @RequestMapping(value = "/sixth/e/show")
    public String Sixth_e() {
        return "/sixth/e";
    }
    @RequestMapping(value = "/sixth/e")
    public String Sixth_e_record(SixthRequest request,ModelMap modelMap,HttpSession httpSession) {
        request.setoName((String)httpSession.getAttribute("oName"));
        sixthService.Sixth_e(request);
        modelMap.put("state",sixthService.Sixth_index(request));
        return "/sixth/index";
    }



}
